home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 February
/
EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso
/
earcd
/
comm2
/
kms20src.lha
/
KMSAUX
/
receiver.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-25
|
3KB
|
136 lines
/*
* Debug Server KMSAUX:
*/
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include "aux-debug.h"
BOOL debugmode = FALSE; /* extra output with TRUE */
FILE *op = NULL; /* file save output option */
LONG main(LONG arc, STRPTR *argv)
{
struct MsgPort *port;
struct DebugMsg *msg;
LONG port_signal, break_signals, signals;
STRPTR ptr;
/* open the port */
port = CreatePort(AUXDEBUGPORT, 0);
if (!port)
printf("Error creating port \"%s\"\n", AUXDEBUGPORT);
else
printf("Created port \"%s\" successfully.\n", AUXDEBUGPORT);
port_signal = 1 << port->mp_SigBit; /* server port */
break_signals = SIGBREAKF_CTRL_F; /* toggle file save option */
break_signals |= SIGBREAKF_CTRL_C;
break_signals |= SIGBREAKF_CTRL_D; /* turn on Debug info */
break_signals |= SIGBREAKF_CTRL_E; /* Exit */
printf("\nCTRL-F: Toggle save | CTRL-D: Debug info | CTRL-E: Exit\n\n");
/* process until a control-E to exit */
while(TRUE)
{
signals = Wait(port_signal | break_signals);
if (signals & port_signal) /* debug messages first */
{
while (msg = (struct DebugMsg *)GetMsg(port))
{
if (debugmode || msg->flag)
{
if (debugmode)
{
for(ptr = msg->msg; *ptr; ptr++)
if (*ptr < 20 || *ptr > 126)
*ptr = '.';
printf("%s %ld %ld %ld\n", msg->msg, msg->a, msg->b, msg->c);
if (op)
fprintf(op, "%s %ld %ld %ld\n", msg->msg, msg->a, msg->b, msg->c);
}
else
{
printf("%s", msg->msg);
if (op)
fprintf(op, "%s", msg->msg);
}
}
FreeMem(msg->msg, strlen(msg->msg) + 1);
FreeMem(msg, sizeof(struct DebugMsg));
}
}
if (signals & SIGBREAKF_CTRL_D)
{
debugmode = !debugmode;
printf("Got Control_D, debug is %s...\n", (debugmode) ? "on" : "off");
if (op)
fprintf(op, "Got Control_D, debug is %s...\n", (debugmode) ? "on" : "off");
}
if (signals & SIGBREAKF_CTRL_E)
{
printf("Got Control_E, exiting\n");
break;
}
if (signals & SIGBREAKF_CTRL_F)
{
printf("Got Control_F, File save option is turned ");
if (op)
fprintf(op, "Got Control_F, File save option is turned off.\n");
if (op == NULL)
{
printf("on...\n");
op = fopen("T:save.aux", "a");
if (!op)
printf("Error: T:save.aux could not be opened!\n");
}
else /* already logging, turn it off */
{
printf("off...\n");
fclose(op);
op = NULL;
}
}
}
if (port)
{
Forbid();
while (msg = (struct DebugMsg *)GetMsg(port));
DeletePort(port); /* remove the server port */
Permit();
}
if (op)
fclose(op);
exit(0);
}